<html lang="en">
<head>
    <meta charset="utf-8">
    <title>SOAP CARTE</title>
    <style>

        /* Extra small devices (phones, 600px and down) */
        @media only screen and (max-width: 600px) {
            .soap{
                width: 100%;
            }
            .soap-inner{
                width: 100%;
                float:left;
                line-height: 30px;
                margin-bottom: 5px;
                text-align: center;
            }
            .text{
                line-height: 30px;
                display: inline-block;
                vertical-align: middle;
                margin-top: -15px;
            }
            .operator{
                width: 35px;
                height: 30px;
                line-height: 30px;
                display: inline-block;
            }
        }

        /* Small devices (portrait tablets and large phones, 600px and up) */
        @media only screen and (min-width: 600px) {
            .soap{
                width: 100%;
            }
            .soap-inner{
                width: 100%;
                float:left;
                line-height: 30px;
                margin-bottom: 5px;
                text-align: center;
            }
            .text{
                line-height: 30px;
                display: inline-block;
                vertical-align: middle;
                margin-top: -10px;
            }
            .operator{
                width: 35px;
                height: 30px;
                line-height: 30px;
                display: inline-block;
            }
        }

        /* Medium devices (landscape tablets, 768px and up) */
        @media only screen and (min-width: 768px) {
            .soap{
                width: 500px;
                margin: 0 auto;
            }
            .soap-inner{
                width: 50%;
                float:left;
                line-height: 30px;
                margin-bottom: 10px;
                text-align: left;
            }
            .soap-inner:odd{
                padding-left: 20px;
                width: calc(50% -20px);
            }
            .text{
                line-height: 30px;
                display: inline-block;
                margin-top: 0px;
            }
            .operator{
                width: 35px;
                height: 30px;
                float:left;
                margin-left: 30px;
            }
        }

    </style>
    <script
        src="https://code.jquery.com/jquery-2.2.4.min.js"
        integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
        crossorigin="anonymous"></script>
    <script>
        function GetSortOrder(prop) {
            return function(a, b) {
                if (a[prop] > b[prop]) {
                    return 1;
                } else if (a[prop] < b[prop]) {
                    return -1;
                }
                return 0;
            }
        }

        function json2array(json){
            var result = [];
            var keys = Object.keys(json);
            keys.forEach(function(key){
                result.push(json[key]);
            });
            return result;
        }

        function _isContains(json, value) {
            let contains = false;
            Object.keys(json).some(key => {
                contains = typeof json[key] === 'object' ? _isContains(json[key], value) : json[key] === value;
                return contains;
            });
            return contains;
        }

        $.ajax({
            "url":"https://monitor.gamprofessional.com/index.php?r=realtime/default/get-queue-members&queue=935",
            "dataType": "json",
            "success": function (data) {
                var qusers=data;
                setInterval(function() {
                    $.ajax({
                        "url": "https://monitor.gamprofessional.com/index.php?r=realtime/default/stats",
                        "dataType": "json",
                        "success": function (data) {

                            data=json2array(data.members);
                            data.sort(GetSortOrder("Extension"));

                            var soap="";
                            var icon="hred.png";
                            $.each(data, function (i, val) {
                                if(_isContains(qusers,val.Extension)){
                                    if(val.Name.match(/carte/g)) {
                                        var name = val.Name.split("carte");

                                        switch (val.Status) {
                                            case "1":
                                                icon="hgreen.png";
                                                if(val.Paused=="1") {
                                                    icon="hyellow.png";
                                                }
                                                break;
                                            case "2":
                                                icon="hred.png";
                                                if(val.Paused=="1") {
                                                    icon="hblu.png";
                                                }
                                                break;
                                        }

                                        soap+="<img src='https://monitor.gamprofessional.com/images/"+icon+"' style='width: 30px; height: 30px;' ></span> <span class='text' style='height:90px;'>"+val.Extension+" - "+name[0]+"</span></div>";
                                    }
                                }
                            });

                            $(".soap").html(soap);
                        }
                    });
                }, 2000);
            }
        });

    </script>
</head>

</div>
</body>
</html>
